{% extends "./base.html" %}

{% block content %}
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/layer.js"></script>


        <div class="header">

            <h1 class="page-title">部门管理</h1>
                    <ul class="breadcrumb">
            <li><a href="/">首页</a> </li>


            <li class="active">部门管理</li>
                        <input class="layui-btn layui-btn-mini" type="button" name="Submit" onclick="javascript:history.back(-1);" value="返回上一页">
        </ul>

        </div>
        <div class="main-content">

<div class="btn-toolbar list-toolbar">

 <form  role="form" method="get" action="{% url 'deptsearch-view' %}" style="float: left">
 {% csrf_token %}
    <input placeholder="搜索部门" type="text"  class="form-control" id="s" name="word"  style="width:200px;float: left;">

<button class="btn btn-primary" >搜 索</button>
</form>
<div style="float: right">


    <a href="{% url 'adddept-view' %}" class="btn btn-primary"><i class="fa fa-plus"></i> 添加新部门</a>

    <a href="{% url 'updept-view' %}" class="btn btn-default">导入数据</a>

    <input id="openexcelfile" type="file" name="openexcelfile" style="display: none;" />
    <a href="{% url 'xlwtdept-view' %}" class="btn btn-default">导出数据</a>
      <input id="yourinputname" type="file" name="yourinputname" value="上传" style="display: none;" />
    </div>
  <div class="btn-group">
  </div>
</div>


<table id="tableid" class="table table-striped table-bordered table-hover">
  <thead>
    <tr>

      <th width="48%">部门</th>
      <th  width="48%">上级部门</th>
        <th >操作</th>


    </tr>
  </thead>
  <tbody>
  {% with obj_list as dept_list %}
  {% if dept_list %}

      {% for dept in dept_list %}
          {% if dept.delstatus %}
          {% endif %}
           <tr>

      <td><a title="点击修改此条信息" href="/dept/{{ dept.id }}"> {{ dept.deptname }}</a></td>
      <td>{% if not dept.parentdept %}{{ "" }}{% else %}{{ dept.parentdept }}{% endif %}</td>

      <td>

          <a  href="/dept/{{ dept.id }}" title="修改"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;&nbsp;


          <a href="#delModal{{ dept.id }}" role="button" data-toggle="modal" title="删除"><i class="fa fa-trash-o"></i></a>

<!--
            <form name="dedept" action="" id="del_dept"  method='post' onclick="return del_deptjs('{{ dept.deptname }}')">
                 {% csrf_token %}
            <a style="padding-left: 20px" href="#" type="checkbox"class="fa fa-trash-o"></a>
            <a style="display:none" id='deptid' name="dddddd">{{ dept.id }}</a>
                <input name="ddddd" type="text" value="{{ dept.id }}">
                <button type="submit" style="display: none"></button>
            </form>
-->

          <div class="modal small fade" id="delModal{{ dept.id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

<form id="delmodelform{{ dept.id }}" method="post" action="/deldept/{{ dept.id }}/" >
 {% csrf_token %}
  <div class="modal-dialog">

    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <a style="color:red;font-size: x-large">删除部门</a>
        </div>

        <div class="modal-body">
            <p class="error-text"><i class="fa fa-warning modal-icon"></i>您确定要删除部门  <a style="color: red">{{ dept.deptname }}</a><br>如要恢复部门请登录管理员后台操作</p>
        </div>

        <div class="modal-footer">
            <button  class="btn btn-danger" data-dismiss="modal" onclick="submitForm('{{ dept.id }}');">Delete</button>
            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>

        </div>
      </div>
    </div>
</form>
</div>

      </td>

    </tr>
      {% endfor %}


  {% endif %}

{% endwith %}
  </tbody>

</table>

<!--分页 -->

        {% if obj_list %}
            <div  style="position:absolute;bottom:0px;">
        {% include 'include/pagination.html' %}
            </div>
        {% endif %}




</div>
<script>



 function submitForm(e) {

                document.getElementById("delmodelform"+e).submit();

     }


function del_deptjs(e)
{
    var getid = document.getElementById("deptid").innerHTML;
     var from = document.getElementById("del_dept")
    layer.confirm('确认删除部门：（'+e+"）    吗？", {icon: 3, title:'警告:此部门下的所有员工也会被删除！'}, function(index){
  //do something


        //form.action= "/deldept/4/";
        //form.submit();
     $("#del_dept").submit();
    //document.dedept.action="/deldept/4";
  layer.close(index);
});





}
</script>


{% endblock %}